<#include "../common/layout/__mainlayout.html">
<#include "../common/__pagination.html">

    <!--设置面包屑-->
    <#assign pageBreadCrumbs>
        <li class="active"><a href="#">
            <#if parentType =="appUploadFlag">
                    上传&审核
                <#else>
                    应用管理
            </#if>
            </a></li>
        <#if fromType == "listSoftItems">
            <li class="active">软件版本管理</li>
        </#if>
        <#if fromType == "listDraft">
            <li class="active">草稿管理</li>
        </#if>
        <#if fromType == "listWaitCheck">
            <li class="active">待审核列表</li>
        </#if>
        <#if fromType == "myCheckedList">
            <li class="active">我审核的应用</li>
        </#if>


    </#assign>


    <#assign pageCss>
        <!-- page specific plugin styles -->
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/jquery-ui.custom.css"/>
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/chosen.css"/>
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/datepicker.css"/>
        <link rel="stylesheet" href="${ctx}/static/admin/assets/css/daterangepicker.css"/>

    </#assign>

    <#assign pageJavascript>
        <script type="text/javascript">
            $(document).ready(function () {
                //初始化范围选择器
                $('input[name=publishDateRange]').daterangepicker({
                    'applyClass' : 'btn-sm btn-success',
                    'cancelClass' : 'btn-sm btn-default',
                    locale: {
                        applyLabel: '确定',
                        cancelLabel: '取消'
                    }
                });

                //初始化范围选择器
                $('input[name=createDateRange]').daterangepicker({
                    'applyClass' : 'btn-sm btn-success',
                    'cancelClass' : 'btn-sm btn-default',
                    locale: {
                        applyLabel: '确定',
                        cancelLabel: '取消'
                    }
                })

                $("#payType").val(${query.payType!});
                $("#safeState").val(${query.safeState!});
                $("#softSrc").val(${query.softSrc!});
                $("#isAccredit").val(${query.isAccredit!});
                $("#state").val(${query.state!});
                $("#checkAdminName").val(${query.checkAdminName!});
                $("#categoryId").val(${query.categoryId!});
                $("#categoryId2").val(${query.categoryId2!});
                $("#categoryId3").val(${query.categoryId3!});

                var fromType = $("#fromType").val();
                $("#"+fromType).addClass("active");

                $('[data-rel=tooltip]').tooltip();

                if (!ace.vars['touch']) {
                    $('.chosen-select').chosen({allow_single_deselect: true});
                }

                // 清除远程modal数据
                $("#editModal").on("hidden.bs.modal", function () {
                    $(this).removeData("bs.modal");
                });

                // 删除按钮
                $("a.delete").on(ace.click_event, function (e) {
                    submitClickListener(this,e,"删除");
                });

                // 上架按钮
                $("a.upState").on(ace.click_event, function (e) {
                    submitClickListener(this,e,"上架");
                });

                // 下架按钮
                $("a.downState").on(ace.click_event, function (e) {
                    submitClickListener(this,e,"下架");
                });

                // 显示按钮
                $("a.showState").on(ace.click_event, function (e) {
                    submitClickListener(this,e,"展示");
                });

                // 隐藏按钮
                $("a.hiddenState").on(ace.click_event, function (e) {
                    submitClickListener(this,e,"隐藏");
                });



                function submitClickListener(obj,e,title){
                    var currentA = obj;
                    e.preventDefault();
                    bootbox.confirm({
                                message: "确定"+title+"该版本?",
                                buttons: {
                                    confirm: {
                                        label: "确定",
                                        className: "btn-primary btn-sm"
                                    },
                                    cancel: {
                                        label: "取消",
                                        className: "btn-sm"
                                    }
                                },
                                callback: function (result) {
                                    if (result) {
                                        url = $(currentA).attr("href");
                                        $.get(url, { },function(data){
                                            if(data){
                                                window.location.href=window.location.href;
                                            }
                                        });
                                    }
                                }
                            }
                    );
                }

                $("#categoryId").change(function () {
                    //清除二级下拉列表
                    $("#categoryId2").empty();
                    $("#categoryId3").empty();
                    if($(this).val() !=0){

                        $("#categoryId2").append($("<option/>").text("--请选择二级分类--").attr("value","0"));
                        //要请求的二级下拉JSON获取页面
                        var url="${ctx}/admin/category/categoryList.do";
                        //将选中的一级下拉列表项的id传过去
                        $.getJSON(url, { parentId:$(this).val() },function (data) {
                            //对请求返回的JSON格式进行分解加载
                            $(data.data).each(function () {
                                $("#categoryId2").append($("<option/>").text(this.categoryName).attr("value",this.id));
                            });
                        });
                    }
                });

                $("#categoryId2").change(function () {
                    //清除二级下拉列表
                    $("#categoryId3").empty();
                    if($(this).val() !=0){
                        $("#categoryId3").append($("<option/>").text("--请选择三级分类--").attr("value","0"));
                        //要请求的二级下拉JSON获取页面
                        var url="${ctx}/admin/category/categoryList.do";
                        //将选中的一级下拉列表项的id传过去
                        $.getJSON(url, { parentId:$(this).val() },function (data) {
                            //对请求返回的JSON格式进行分解加载
                            $(data.data).each(function () {
                                $("#categoryId3").append($("<option/>").text(this.categoryName).attr("value",this.id));
                            });
                        });
                    }

                });

            });
        </script>
    </#assign>


    <@mainlayout pageBreadCrumbs=pageBreadCrumbs pageCss=pageCss pageJavascript=pageJavascript
        currentMenu="${parentType}-${fromType}">

            <form id="searchForm" class="form-search form-inline"
                <#if fromType == "listSoftItems">
                    action="${ctx}/admin/soft/listSoftItems.html"
                </#if>
                <#if fromType == "listDraft">
                    action="${ctx}/admin/soft/listDraft.html"
                </#if>
                <#if fromType == "listWaitCheck">
                    action="${ctx}/admin/soft/listWaitCheck.html"
                </#if>
                <#if fromType == "myCheckedList">
                    action="${ctx}/admin/soft/myCheckedList.html"
                </#if>

                >
                <div class="row">
                    <div class="widget-body">
                        <div class="widget-main">
                            <div class="form-group  col-xs-12" style="padding-top:10px">
                                <label class="col-xs-1 text-right">软件编号:</label>
                                <input type="number" id="softId" name="softId" class="input-sm col-xs-2"  max="99999999999"  value="${query.softId!}"/>
                                <label class="col-xs-1 text-right">软件版本编号:</label>
                                <input type="number" id="softItemId" name="softItemId" class="input-sm col-xs-2"  max="99999999999"  value="${query.softItemId!}"/>
                                <label class="col-xs-1 text-right">软件具体名称:</label>
                                <input type="text" id="itemName" name="itemName" class="input-sm col-xs-2" value="${query.itemName!}"/>
                                <label class="col-xs-1 text-right">软件包名:</label>
                                <input type="text" id="packageName" name="packageName" class="input-sm col-xs-2" value="${query.packageName!}"/>
                            </div>

                            <div class="form-group col-xs-12" style="padding-top:10px">
                                <#if fromType == "listDraft" || fromType == "listWaitCheck">
                                    <input type="hidden" name="state" class="input-sm col-xs-2" value="${state!}"/>
                                    <#else>
                                        <label class="col-xs-1 text-right">状态:</label>
                                        <select class="col-xs-2" name="state" id="state"  data-placeholder="Choose a State...">
                                            <option value="-99">--全部--</option>
                                            <#list softItemStatus?keys as key>
                                                <option value="${softItemStatus[key]?default('')}">${key}</option>
                                            </#list>
                                        </select>
                                </#if>

                                <#if checkAdminId??>
                                    <input type="hidden" name="checkAdminId" class="input-sm col-xs-2" value="${checkAdminId!}"/>
                                    <#else>
                                        <label class="col-xs-1 text-right" for="checkAdminName">审核人:</label>
                                        <input type="text"  name="checkAdminName" id="checkAdminName" class="col-xs-2" />
                                </#if>

                                <label class="col-xs-1 text-right" for="publishDateRange">上架时间:</label>
                                <input  type="text" class="col-xs-2" readonly="readonly"　 　 name="publishDateRange" id="publishDateRange"  value="${query.publishDateRange!}"/>
                            </div>


                            <div class="form-group col-xs-12" style="padding-top:10px">
                                <label class="col-xs-1 text-right" for="payType">付费方式:</label>
                                <select class="col-xs-2"  name="payType" id="payType"  data-placeholder="Choose a State...">
                                    <option value="-99" >请选择</option>
                                    <option value="0">免费</option>
                                    <option value="1">付费</option>
                                    <option value="2">限时免费</option>
                                </select>

                                <label class="col-xs-1 text-right" for="safeState">安全级别:</label>
                                <select class="col-xs-2"  name="safeState" id="safeState" data-placeholder="Choose a State...">
                                    <option value="-99" >请选择</option>
                                    <#list safeStates as state>
                                        <option value="${state.itemValue}" >
                                            ${(state.itemTitle)!}
                                        </option>
                                    </#list>
                                </select>

                                <label class="col-xs-1 text-right" for="softSrc">软件来源:</label>
                                <select class="col-xs-2"  name="softSrc" id="softSrc" data-placeholder="Choose a State...">
                                    <option value="-99" >请选择</option>
                                    <#list softSrcs as src>
                                        <option value="${src.itemValue}" >
                                            ${(src.itemTitle)!}
                                        </option>
                                    </#list>
                                </select>

                                <label class="col-xs-1 text-right" for="isAccredit">是否授权:</label>
                                <select class="col-xs-2" name="isAccredit" id="isAccredit" data-placeholder="Choose a State..." >
                                    <option value="-99" >请选择</option>
                                    <option value="1" >是</option>
                                    <option value="0" >否</option>
                                </select>
                            </div>
                            <div class="form-group col-xs-12" style="padding-top:10px">
                                <label class="control-label col-xs-12 col-sm-1 text-right" for="categoryId">软件分类:</label>
                                <select class="col-xs-2" name="categoryId" id="categoryId" data-placeholder="请选择一级分类">
                                    <option value="0">--请选择一级分类--</option>
                                    <#list firstCatagories as first>
                                        <option value="${first.id}" >
                                            ${(first.categoryName)!}
                                        </option>
                                    </#list>
                                </select>
                                &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                                <select class="col-xs-2" name="categoryId2" id="categoryId2" data-placeholder="请选择二级分类">
                                    <option value="0">请选择二级分类</option>
                                    <#if secondCatagories??>
                                        <#list secondCatagories as sec>
                                            <option value="${sec.id}" >
                                                ${(sec.categoryName)!}
                                            </option>
                                        </#list>
                                    </#if>

                                </select>
                                &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;
                                <select class="col-xs-2" name="categoryId3" id="categoryId3" data-placeholder="请选择三级分类">
                                    <option value="0">请选择三级分类</option>
                                    <#if thirdCatagories??>
                                        <#list thirdCatagories as third>
                                            <option value="${third.id}" >
                                                ${(third.categoryName)!}
                                            </option>
                                        </#list>
                                    </#if>

                                </select>
                            </div>


                            <div class="form-group  col-xs-12" style="margin-bottom:2px;margin-top:2px">
                                <div class="col-xs-1 text-right" ><input type="button" id="searchBtn" class="btn btn-sm btn-primary" value="查询"/>&nbsp;</div>
                            </div>

                        </div>
                    </div>
                </div>

            <table id="contentTable" class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th width="62" align="center">ICON</th>
                    <th width="40" align="center">软件版本编号</th>
                    <th width="60" align="left">软件具体名称</th>
                    <th width="60" align="left">软件包名</th>
                    <th width="40" align="left">版本名称</th>
                    <th width="40" align="left">下载量</th>
                    <th width="70" align="left">一级分类</th>
                    <th width="70" align="left">二级分类</th>
                    <th width="70" align="left">三级分类</th>
                    <th width="40" align="left">最新版本</th>
                    <th width="40" align="left">审核人</th>
                    <th width="40" align="left">上架时间</th>
                    <th width="140" align="center">操作</th>
                </tr>
                </thead>
                <tbody>
                    <#list softItems.listData as softItem>
                        <#if softItem??>
                            <tr>
                                <td><img width="62" src="${staticHost}${softItem.iconUrl!}"  onerror="this.src='${ctx}/static/admin/assets/img/imgerror.png'" alt="未上传ICON图" /></td>
                                <td width="60" align="left">${softItem.softItemId!}</td>
                                <td width="40" align="left">${softItem.softName!}</td>
                                <td width="60" align="left">${softItem.packageName!}</td>
                                <td width="40" align="left">${softItem.versionName!}</td>
                                <td width="40" align="left">${softItem.vdownloadNumber!}</td>
                                <td width="70" align="left">${softItem.firstCategoryName!}</td>
                                <td width="70" align="left">${softItem.secCategoryName!}</td>
                                <td width="70" align="left">${softItem.thirdCategoryName!}</td>
                                <td width="40" align="left">
                                    <#if softItem.isLastVersion==1>
                                        是
                                        <#else>
                                            否
                                    </#if>
                                    </td>
                                <td width="40" align="left">${softItem.checkAdminName!}</td>
                                <td width="40" align="left">${softItem.publishTimeShow!}</td>
                                <td width="140" >
                                    <div class="hidden-sm hidden-xs action-buttons">
                                        <a class="green tooltip-success view" href="${ctx}/admin/soft/viewSoftItem.do?id=${softItem.softItemId!}" data-rel="tooltip" ><span class="label label-default">查看</span></a>
                                        <a class="green tooltip-success edit" href="${ctx}/admin/soft/editSoftItem.do?id=${softItem.softItemId!}" data-rel="tooltip"><span class="label label-success">编辑</span></a>
                                        <a class="red tooltip-error delete" href="${ctx}/admin/soft/delSoftItem.do?id=${softItem.softItemId!}" data-rel="tooltip"> <span class="label label-danger">删除</span> </a>
                                        <#if softItem.state != 3 >
                                            <a class="green tooltip-warning upState" href="${ctx}/admin/soft/upSoftItem.do?id=${softItem.softItemId!}"  data-rel="tooltip" > <span class="label label-warning">上架</span></a>
                                            <#else>
                                                <a class="green tooltip-warning downState" href="${ctx}/admin/soft/downSoftItem.do?id=${softItem.softItemId!}"  data-rel="tooltip"  > <span class="label label-warning">下架</span></a>
                                        </#if>
                                        <#if softItem.state == 3 >
                                            <a class="green tooltip-warning hiddenState" href="${ctx}/admin/soft/hiddenSoftItem.do?id=${softItem.softItemId!}"  data-rel="tooltip"  > <span class="label label-info">隐藏</span></a>
                                            <#else>
                                                <a class="green tooltip-warning showState" href="${ctx}/admin/soft/showSoftItem.do?id=${softItem.softItemId!}"  data-rel="tooltip"  > <span class="label label-info">展示</span></a>
                                        </#if>
                                    </div>
                                </td>

                            </tr>
                        </#if>
                    </#list>
                </tbody>
            </table>
            <input type="hidden" id="fromType" name="fromType" value="${fromType}">
            <@pagination softItems!/>
            </form>
            <div id="editModal" class="modal fade">
                <div class="modal-dialog"style="width: 1200px;">
                    <div class="modal-content">
                    </div>
                </div>
            </div>

</@mainlayout>